home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / corelib / ncbimisc.h < prev    next >
Text File  |  1996-07-05  |  9KB  |  226 lines

  1. /*   ncbimisc.h
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE                          
  5. *               National Center for Biotechnology Information
  6. *                                                                          
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and 
  10. *  thus cannot be copyrighted.  This software/database is freely available 
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government have not placed any restriction on its use or reproduction.
  13. *
  14. *  Although all reasonable efforts have been taken to ensure the accuracy
  15. *  and reliability of the software and data, the NLM and the U.S.
  16. *  Government do not and cannot warrant the performance or results that
  17. *  may be obtained by using this software or data. The NLM and the U.S.
  18. *  Government disclaim all warranties, express or implied, including
  19. *  warranties of performance, merchantability or fitness for any particular
  20. *  purpose.
  21. *
  22. *  Please cite the author in any work or product based on this material.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbimisc.h
  27. *
  28. * Author:  Gish, Kans, Ostell, Schuler
  29. *
  30. * Version Creation Date:   10/23/91
  31. *
  32. * $Revision: 2.11 $
  33. *
  34. * File Description: 
  35. *       prototypes of miscellaneous functions
  36. *
  37. * Modifications:
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. * 04-15-93 Schuler     Changed _cdecl to LIBCALL
  42. * 06-15-93 Schuler     SGML functions moved to ncbisgml.c
  43. * 06-15-93 Schuler     Added macros for Gestalt functins.
  44. *
  45. * ==========================================================================
  46. */
  47.  
  48. #ifndef _NCBIMISC_
  49. #define _NCBIMISC_
  50.  
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54.  
  55. /* Obtain length of ASCII representation of signed and unsigned long integers */
  56. /* opts&1 ==> use commas before thousands, millions, etc. when |value| >=10000*/
  57. /* opts&2 ==> use commas before thousands, millions, etc. when |value| >=1000 */
  58. /* opts&4 ==> prepend + sign to any positive values */
  59. int LIBCALL Nlm_Lwidth PROTO((long x, int opts));
  60. int LIBCALL Nlm_Ulwidth PROTO((unsigned long x, int opts));
  61.  
  62. /* convert integers to ASCII in static storage */
  63. /* Same 1,2,4 opts as Nlm_Lwidth and Nlm_Ulwidth */
  64. char * LIBCALL Nlm_Ltostr PROTO((long x, int opts));
  65. char * LIBCALL Nlm_Ultostr PROTO((unsigned long x, int opts));
  66.  
  67. /* Sorting */
  68. void LIBCALL Nlm_HeapSort PROTO((VoidPtr base, Nlm_sizeT nel, Nlm_sizeT width, int (LIBCALLBACK *cmp) (VoidPtr, VoidPtr) ));
  69.  
  70.  
  71. /*****************************************************************************
  72. *
  73. *   DataVal = a universal data type
  74. *   ValNode = a linked list of DataVal
  75. *
  76. *****************************************************************************/
  77.  
  78.  
  79. typedef union dataval { 
  80.     Nlm_VoidPtr ptrvalue;
  81.     Nlm_Int4 intvalue;
  82.     Nlm_FloatHi realvalue;
  83.     Nlm_Boolean boolvalue;
  84. }    DataVal, PNTR DataValPtr;
  85.  
  86. typedef struct valnode {     
  87.     Nlm_Uint1 choice;            /* to pick a choice */
  88.     DataVal data;            /* attached data */
  89.     struct valnode PNTR next;   /* next in linked list */
  90. } ValNode, PNTR ValNodePtr;
  91.  
  92. /*****************************************************************************
  93. *
  94. *   ValNodeNew(vnp)
  95. *      adds after last node in list if vnp not NULL
  96. *   
  97. *   ValNodeAdd(head)
  98. *      adds after last node in list if *head not NULL
  99. *      If *head is NULL, sets it to the new ValNode
  100. *      returns pointer to the NEW node added
  101. *
  102. *   ValNodeLink(head, newnode)
  103. *      adds newnode at end of chain
  104. *      if (*head == NULL) *head = newnode
  105. *      ALWAYS returns pointer to START of chain
  106. *
  107. *   ValNodeAddStr (head, choice, str)
  108. *      adds like ValNodeAdd()
  109. *      sets newnode->choice = choice (if choice does not matter, use 0)
  110. *      sets newnode->data.ptrvalue = str
  111. *         does NOT copy str
  112. *      if str == NULL, does NOT add a ValNode
  113. *
  114. *   ValNodeCopyStr (head, choice, str)
  115. *      adds like ValNodeAdd()
  116. *      sets newnode->choice = choice (if choice does not matter, use 0)
  117. *      sets newnode->data.ptrvalue = str
  118. *         makes a COPY of str
  119. *      if str == NULL, does NOT add a ValNode
  120. *   
  121. *   ValNodeAddInt (head, choice, value)
  122. *      adds like ValNodeAdd()
  123. *      sets newnode->choice = choice (if choice does not matter, use 0)
  124. *      sets newnode->data.intvalue = value
  125. *
  126. *   ValNodeAddBoolean (head, choice, value)
  127. *      adds like ValNodeAdd()
  128. *      sets newnode->choice = choice (if choice does not matter, use 0)
  129. *      sets newnode->data.boolvalue = value
  130. *
  131. *   ValNodeAddFloat (head, choice, value)
  132. *      adds like ValNodeAdd()
  133. *      sets newnode->choice = choice (if choice does not matter, use 0)
  134. *      sets newnode->data.realvalue = value
  135. *
  136. *   ValNodeAddPointer (head, choice, value)
  137. *      adds like ValNodeAdd()
  138. *      sets newnode->choice = choice (if choice does not matter, use 0)
  139. *      sets newnode->data.realvalue = value
  140. *
  141. *   ValNodeFree(vnp)
  142. *       frees whole chain of ValNodes
  143. *       Does NOT free associated data pointers
  144. *
  145. *   ValNodeFreeData(vnp)
  146. *       frees whole chain of ValNodes
  147. *       frees associated data pointers - BEWARE of this if these are not
  148. *           allocated single memory block structures.
  149. *
  150. *   ValNodePtr ValNodeExtract(headptr, choice)
  151. *       removes first node in chain where ->choice == choice
  152. *       rejoins chain after removing the node
  153. *       sets node->next to NULL
  154. *
  155. *   ValNodePtr ValNodeExtractList(headptr, choice)
  156. *       removes ALL nodes in chain where ->choice == choice
  157. *       rejoins chain after removing the nodes
  158. *       returns independent chain of extracted nodes
  159. *
  160. *   ValNodeFindNext (head, curr, choice)
  161. *       Finds next ValNode with vnp->choice == choice after curr
  162. *       If curr == NULL, starts at head of list
  163. *       If choice < 0 , returns all ValNodes
  164. *       Returns NULL, when no more found
  165. *   
  166. *****************************************************************************/
  167. ValNodePtr LIBCALL ValNodeNew PROTO((ValNodePtr vnp));
  168. ValNodePtr LIBCALL ValNodeAdd PROTO((ValNodePtr PNTR head));
  169. ValNodePtr LIBCALL ValNodeLink PROTO((ValNodePtr PNTR head, ValNodePtr newnode));
  170. ValNodePtr LIBCALL ValNodeAddStr PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_CharPtr str));
  171. ValNodePtr LIBCALL ValNodeCopyStr PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_CharPtr str));
  172. ValNodePtr LIBCALL ValNodeAddInt PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_Int4 value));
  173. ValNodePtr LIBCALL ValNodeAddBoolean PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_Boolean value));
  174. ValNodePtr LIBCALL ValNodeAddFloat PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_FloatHi value));
  175. ValNodePtr LIBCALL ValNodeAddPointer PROTO((ValNodePtr PNTR head, Nlm_Int2 choice, Nlm_VoidPtr value));
  176. ValNodePtr LIBCALL ValNodeFree PROTO((ValNodePtr vnp));
  177. ValNodePtr LIBCALL ValNodeFreeData PROTO((ValNodePtr vnp));
  178. ValNodePtr LIBCALL ValNodeExtract PROTO((ValNodePtr PNTR headptr, Nlm_Int2 choice));
  179. ValNodePtr LIBCALL ValNodeExtractList PROTO((ValNodePtr PNTR headptr, Nlm_Int2 choice));
  180. ValNodePtr LIBCALL ValNodeFindNext PROTO((ValNodePtr head, ValNodePtr curr, Nlm_Int2 choice));
  181.  
  182. /*** old prototypes ******
  183. ValNodePtr LIBCALL ValNodeLink PROTO((ValNodePtr vnp, ValNodePtr newnode));
  184. ValNodePtr LIBCALL ValNodeExtract PROTO((ValNodePtr PNTR headptr, Nlm_Uint1 choice));
  185. **************************/
  186.  
  187. ValNodePtr  LIBCALL NodeListNew PROTO((void));
  188. ValNodePtr  LIBCALL NodeListFree PROTO((ValNodePtr head));
  189. Nlm_Int2    LIBCALL NodeListLen PROTO((ValNodePtr head));
  190. ValNodePtr  LIBCALL NodeListFind PROTO((ValNodePtr head, Nlm_Int2 item, Nlm_Boolean extend));
  191. Nlm_Boolean LIBCALL NodeListRead PROTO((ValNodePtr head, Nlm_Int2 item, Nlm_VoidPtr ptr, Nlm_sizeT size));
  192. Nlm_Boolean LIBCALL NodeListWrite PROTO((ValNodePtr head, Nlm_Int2 item, Nlm_VoidPtr ptr, Nlm_sizeT size));
  193. Nlm_Boolean LIBCALL NodeListAppend PROTO((ValNodePtr head, Nlm_VoidPtr ptr, Nlm_sizeT size));
  194. Nlm_Boolean LIBCALL NodeListInsert PROTO((ValNodePtr head, Nlm_Int2 item, Nlm_VoidPtr ptr, Nlm_sizeT size));
  195. Nlm_Boolean LIBCALL NodeListReplace PROTO((ValNodePtr head, Nlm_Int2 item, Nlm_VoidPtr ptr, Nlm_sizeT size));
  196. Nlm_Boolean LIBCALL NodeListDelete PROTO((ValNodePtr head, Nlm_Int2 item));
  197.  
  198.  
  199.     /****** Choice is a compact variant of ValNode **********/
  200.  
  201. typedef union _IntPnt_ {
  202.     Int4 intvalue;
  203.     Pointer ptrvalue;
  204. } IntPnt;
  205.  
  206. typedef struct _Choice_ {
  207.     Uint1 choice;
  208.     IntPnt value;
  209. } Choice, PNTR ChoicePtr;
  210.  
  211.  
  212. #define Lwidth    Nlm_Lwidth
  213. #define Ulwidth    Nlm_Ulwidth
  214. #define Ltostr    Nlm_Ltostr
  215. #define Ultostr    Nlm_Ultostr
  216. #define HeapSort    Nlm_HeapSort
  217.  
  218.  
  219. /* Error codes for the CTX_NCBIMISC context */
  220.  
  221. #ifdef __cplusplus
  222. }
  223. #endif
  224.  
  225. #endif /* !_NCBIMISC_ */
  226.